﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class KHACHSAN_DAO
    {

        #region 1. Inserting
        public static bool ThemKhachSan(KHACHSAN_DTO ks)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKS", ks.MaKS));
                sqlParams.Add(new SqlParameter("@TenKS", ks.TenKS));
                sqlParams.Add(new SqlParameter("@TienPhong", ks.TienPhong));
                sqlParams.Add(new SqlParameter("@MaTP", ks.MaTP));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("usp_InsertKHACH_SAN", sqlParams);

                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region 2. Updating
        public static bool SuaKhachSan(KHACHSAN_DTO ks)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKS", ks.MaKS));
                sqlParams.Add(new SqlParameter("@TenKS", ks.TenKS));
                sqlParams.Add(new SqlParameter("@TienPhong", ks.TienPhong));
                sqlParams.Add(new SqlParameter("@MaTP", ks.MaTP));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("usp_UpdateKHACH_SAN", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region 3. Deleting
        public static bool XoaKhachSan(int MaKS)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKS", MaKS));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("usp_DeleteKHACH_SAN", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        public static List<KHACHSAN_DTO> SelectKhachSansByAndMaTP(int MaTP)
        {
            List<KHACHSAN_DTO> list = new List<KHACHSAN_DTO>();
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaTP", MaTP));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("usp_SelectKHACH_SANsByAndMaTP", sqlParams);
                foreach (DataRow dr in dt.Rows)
                {
                    KHACHSAN_DTO ks = new KHACHSAN_DTO();
                    ks.MaKS = int.Parse(dr["MaKS"].ToString());
                    ks.TenKS = dr["TenKS"].ToString();
                    ks.TienPhong = float.Parse(dr["TienPhong"].ToString());
                    ks.MaTP = int.Parse(dr["MaTP"].ToString());
                    list.Add(ks);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }

    }
}
